﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using XDataBase.Demo.Data.Controller;
using XDataBase.Demo.Data.Model;

namespace XDataBase.Demo
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            getListData();
        }

        /// <summary>
        /// 获取分页数据示例
        /// </summary>
        private void getListData()
        {
            var controller = new TDemoController();
            var result = controller.getListData(new TDemoModel() { 
                pageSize = 20,
                pageNumber = 1,
                sortColumn = "Column1",
                sortDirection = System.ComponentModel.ListSortDirection.Ascending,
                fullTextSearch = ""
            });
            if (result.isSuccess)
            {
                demoDataGrid.ItemsSource = result.data;
            }
            else
            {
                Console.WriteLine(result.exception.Message);
            }
        }

        /// <summary>
        /// 新增/更新示例
        /// </summary>
        private void add()
        {
            var datas = new List<TDemoModel>();
            datas.Add(new TDemoModel()
            {
                Column1 = Guid.NewGuid().ToString(),
                Column2 = false,
                Column3 = 100,
                Column4 = DateTime.Now
            });
            datas.Add(new TDemoModel()
            {
                Column1 = Guid.NewGuid().ToString(),
                Column2 = false,
                Column3 = 100,
                Column4 = DateTime.Now
            });

            var controller = new TDemoController();
            var result = controller.updateMany(datas);
            if (result.isSuccess)
            {
                //成功
            }
            else
            {
                Console.WriteLine(result.exception.Message);
            }
        }

        /// <summary>
        /// 删除示例
        /// </summary>
        private void delete()
        {
            var controller = new TDemoController();
            var result = controller.delete(new TDemoModel()
            {
                ID = 1
            });
            if (result.isSuccess)
            {
                //成功
            }
            else
            {
                Console.WriteLine(result.exception.Message);
            }
        }
    }
}
